<?php
include("../conn.php");
include 'a-cookie.php';
$id = $_SESSION['a-id'];
$year = $_SESSION['a-Year'];
$rank = $_SESSION['a-rank'];
?>
<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>答辩汇总-管理员端</title>
    <link rel="stylesheet" type="text/css" href="../css/htmleaf-demo.css">
    <link rel="stylesheet" type="text/css" href="../css/nav.css">
    <link rel="stylesheet" type="text/css" href="../fonts/iconfont.css">

    <link rel="stylesheet" href="../css/bootstrap-theme.css"/>

    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <link rel="stylesheet" href="../css/bootstrap-theme.min.css"/>
    <link rel="stylesheet" href="../css/bootstrap.css"/>
    <script type="text/javascript" src="../js/jquery-1.11.0.min.js"></script>
    <link rel="stylesheet" type="text/css" href="../css/style.css">

    <script>
        function hz_all(msg) {
            var flag = confirm("确定进行答辩汇总？");

            if (flag) {
                $.ajax({
                    type: "post",
                    url: "a-all-btn.php",
                    data: "method=" + msg,
                    success: function (msg) {
                        alert("提示: " + msg);
                    }
                });
                window.location.href = "a-all.php";
            }
            else {
                alert("你已经取消此次答辩汇总");
            }
        }
        function hz_one(msg) {
            var flag = confirm("确定进行答辩汇总？");
            if (flag) {
                $.ajax({
                    type: "post",
                    url: "a-all-btn.php",
                    data: "method=" + msg,
                    success: function (msg) {
                        alert("提示: " + msg);
                    }
                });
                window.location.href = "a-all.php";
            } else {
                alert("你已经取消此次答辩汇总");
            }
        }


    </script>


</head>

<body class="bodycolor">

<nav class="navbar navbar-default navbar-fixed-top" style="clear: left;">
    <div class="container">
        <div class="navbar-right navfont" id="navbar-collapse">
            <p>华软网络技术系毕业管理系统</p>
        </div>
        <a href="a-cookie.php?cookie=out" id="out">退出</a>
    </div>

</nav>

<div class="nav topx navbackground-a" id="nav">
    <div>

        <div style="border-bottom:1px solid rgba(255,255,255,.1)"><img src="../images/mini.png"></div>
    </div>
    <ul>
        <?
        if($_SESSION["a-rank"]==0)
        {?>

            <li class="nav-item">
                <a href="a-index.php"><i class="my-icon nav-icon icon_2"></i><span>首页</span><i class="my-icon nav-more"></i></a>

            </li>
            <li class="nav-item">
                <a href="a-newsManage.php"><i class="my-icon nav-icon icon_5"></i><span>开放/新闻管理</span><i
                        class="my-icon nav-more"></i></a>
            </li>


            <li class="nav-item">
                <a href="a-all.php"><i class="my-icon nav-icon icon_6"></i><span>答辩汇总</span><i class="my-icon nav-more"></i></a>

            </li>
            <li class="nav-item">
                <a href="#"><i class="my-icon nav-icon icon_3"></i><span>答辩分组</span><i class="my-icon nav-more"></i></a>
                <ul>
                    <li>
                        <a href="a-denfenAsign.php"><span>小组分配</span></a>
                    </li>
                    <li>
                        <a href="a-denfenInterAsign.php"><span>组内分配</span></a>
                    </li>
                </ul>
            </li>
            <li class="nav-item">
                <a href="#"><i class="my-icon nav-icon icon_5"></i><span>资料管理</span><i class="my-icon nav-more"></i></a>
                <ul>
                    <li>
                        <a href="a-sInfromationmange.php"><span>学生资料管理</span></a>
                    </li>
                    <li>
                        <a href="a-tInfromationmange.php"><span>教师资料管理</span></a>
                    </li>
                </ul>
            </li>
        <?}else{
            ?>

            <li class="nav-item">
                <a href="a-index.php"><i class="my-icon nav-icon icon_2"></i><span>首页</span><i class="my-icon nav-more"></i></a>

            </li>
            <li class="nav-item">
                <a href="a-all.php"><i class="my-icon nav-icon icon_6"></i><span>答辩汇总</span><i class="my-icon nav-more"></i></a>

            </li>
            <li class="nav-item">
                <a href="#"><i class="my-icon nav-icon icon_3"></i><span>答辩分组</span><i class="my-icon nav-more"></i></a>
                <ul>
                    <li>
                        <a href="a-denfenInterAsign.php"><span>组内分配</span></a>
                    </li>
                </ul>
            </li>
        <? }
        ?>
    </ul>
</div>
<!--查询语句-->


<div class="indexborder">
    <?
    if ($rank == 0) {
        ?>
        <center>
            <div class="indexdiv1 panel panel-default auto" align="center">
                <div class="panel" style="border:1px solid #807345"><!--panel-warning-->
                    <div class="panel-heading" style="background-color: #807345;">
                        <h3 class="panel-title ">答辩汇总</h3>
                    </div>
                    <div class="panel-body">
                        <div class="table-responsive">


                            <table class="table">

                                <thead>

                                <tr>
                                    <th>指导教师</th>
                                    <th>答辩教师</th>
                                    <th>课题名</th>
                                    <th>学号</th>
                                    <th>学生名</th>
                                    <th>项8</th>
                                    <th>项9</th>
                                    <th>项10</th>
                                    <th>项11</th>
                                    <th>评语</th>
                                </tr>
                                </thead>
                                <?php
                                $data = "y";//检查答辩汇总表有没有数据,如果有，y；没有，n；
                                $sql_data = " select * from dzsubject";
                                $result_data = $conn->query($sql_data);
                                //$count=$row_avg['count'];
                                $row_data = $result_data->fetch_array();

                                if ($result_data->num_rows > 0) {
                                    //进行了答辩汇总
                                    $data = "y";
                                    $sql_avg = " select dzsubject.* ,Project.ProjectName ,teacher.TeacherName, student.StudentName, student.StudentId,remark
		from dzsubject
		LEFT JOIN Project ON dzsubject.Project_ProjectId = project.ProjectId
		LEFT JOIN student ON project.Student_StudentId = student.StudentId
		LEFT JOIN teacher ON student.Teacher_TeacherId = teacher.TeacherId
		";
                                } else {
                                    //还没有进行答辩汇总
                                    $data = "n";
                                    $sql_avg = "SELECT  Project.ProjectName, teacher.TeacherName, student.StudentName, student.StudentId
				from ReplyMark
				LEFT JOIN Project ON ReplyMark.Project_ProjectId = project.ProjectId
				LEFT JOIN student ON project.Student_StudentId = student.StudentId
				LEFT JOIN teacher ON student.Teacher_TeacherId = teacher.TeacherId
				group by student.StudentId
				order BY replymark.Project_ProjectId";
                                }
                                $result_avg = mysqli_query($conn, $sql_avg);
                                while ($row_avg = mysqli_fetch_array($result_avg)) {
                                    if ($data == "y") {
                                        ?>
                                        <tr class="warning">

                                            <td><?php echo $row_avg['TeacherName'] ?></td>
                                            <td>---</td>
                                            <td><?php echo $row_avg['ProjectName'] ?></td>
                                            <td><?php echo $row_avg['StudentId'] ?></td>
                                            <td><?php echo $row_avg['StudentName'] ?></td>
                                            <td><?php echo $row_avg['Order8'] ?></td>
                                            <td><?php echo $row_avg['Order9'] ?></td>
                                            <td><?php echo $row_avg['Order10'] ?></td>
                                            <td><?php echo $row_avg['Order11'] ?></td>
                                            <td><?= $row_avg['remark'] ?></td>
                                        </tr>
                                    <?php
                                    } else if ($data == "n") {
                                        ?>

                                        <tr class="warning">

                                            <td><?php echo $row_avg['TeacherName'] ?></td>
                                            <td>---</td>
                                            <td><?php echo $row_avg['ProjectName'] ?></td>
                                            <td><?php echo $row_avg['StudentId'] ?></td>
                                            <td><?php echo $row_avg['StudentName'] ?></td>
                                            <td><?php //echo $row_avg['avg_order8'];}?></td>
                                            <td><?php //echo round($row_avg['avg_order9'], 2)?></td>
                                            <td><?php //echo round($row_avg['avg_order10'], 2)?></td>
                                            <td><?php // echo round($row_avg['avg_order11'], 2)?></td>
                                            <td>---</td>
                                        </tr>
                                    <?php } ?>

                                    <?php
                                    $student_id = $row_avg['StudentId'];
                                    $sql_all = "SELECT ReplyMark. * , Project.ProjectName, teacher.TeacherName, student.StudentName, student.StudentId
		FROM ReplyMark
		LEFT JOIN Project ON ReplyMark.Project_ProjectId = project.ProjectId
		LEFT JOIN teacher ON ReplyMark.Teacher_TeacherId = teacher.TeacherId
		LEFT JOIN student ON project.Student_StudentId = student.StudentId
		where student.StudentId=$student_id";
                                    $result_all = mysqli_query($conn, $sql_all);
                                    while ($row_all = mysqli_fetch_array($result_all)) {

                                        ?>
											<tr>
												<tr>
													<td>---</td>
													<td><?php echo $row_all['TeacherName'] ?></td>
													<td>---</td>
													<td>---</td>
													<td>---</td>
													<td><?php echo $row_all['Order8'] ?></td>
													<td><?php echo $row_all['Order9'] ?></td>
													<td><?php echo $row_all['Order10'] ?></td>
													<td><?php echo $row_all['Order11'] ?></td>
													<td><?php echo $row_all['remark'] ?></td>
												</tr>



											</tr>
											<?php
                                    }
                                } ?>





                                </tr>


                            </table>


                        </div>
                    </div>
                </div>

                <!--panel-foot-->

                <div class="panel-footer">
                    <form method="post" >
<!--                        <input type="text" class="maneger_input" id="search_text"/>-->
<!--                        <button class="maneger_button" type="submit">搜索</button>-->
                        <!--将所有成绩进行汇总，求平均分-->
                        <button class="maneger_button" class="btn" value="all" onclick="hz_all('all')">汇总</button>
                    </form>

                </div>

                <from>

            </div>
        </center>
    <? } else if ($rank == 1) { ?>
        <center>
            <div class="indexdiv1 panel panel-default auto" align="center">
                <div class="panel" style="border:1px solid #807345"><!--panel-warning-->
                    <div class="panel-heading" style="background-color: #807345;">
                        <h3 class="panel-title ">答辩汇总</h3>
                    </div>
                    <div class="panel-body">
                        <div class="table-responsive">


                            <table class="table">

                                <thead>

                                <tr>
                                    <th>指导教师</th>
                                    <th>答辩教师</th>
                                    <th>课题名</th>
                                    <th>学号</th>
                                    <th>学生名</th>
                                    <th>项8</th>
                                    <th>项9</th>
                                    <th>项10</th>
                                    <th>项11</th>
                                    <th>评语</th>
                                </tr>
                                </thead>
                                <?php
                                $sql_avg = " SELECT t.TeacherId,t.TeacherName,p.ProjectName,s.StudentId,s.StudentName,dz.Order8,dz.Order9,dz.Order10,dz.Order11,dz.remark from dzsubject as dz
  JOIN replymark as r on r.ReplyMarkId=dz.Project_ProjectId
  JOIN project as p on p.ProjectId = dz.Project_ProjectId
  JOIN teacher as t on t.TeacherId = p.Teacher_TeacherId
  JOIN student as s on s.StudentId = p.Student_StudentId
where r.Teacher_TeacherId=$id
		";
                                $result_avg = mysqli_query($conn, $sql_avg);
                                while ($row_avg = mysqli_fetch_array($result_avg)) {

                                    ?>
                                        <tr class="warning">

                                            <td><?php echo $row_avg['TeacherName'] ?></td>
                                            <td>---</td>
                                            <td><?php echo $row_avg['ProjectName'] ?></td>
                                            <td><?php echo $row_avg['StudentId'] ?></td>
                                            <td><?php echo $row_avg['StudentName'] ?></td>
                                            <td><?php echo $row_avg['Order8'] ?></td>
                                            <td><?php echo $row_avg['Order9'] ?></td>
                                            <td><?php echo $row_avg['Order10'] ?></td>
                                            <td><?php echo $row_avg['Order11'] ?></td>
                                            <td><?= $row_avg['remark'] ?></td>
                                        </tr>


                                    <?php
                                    $student_id = $row_avg['StudentId'];
                                    $sql_all = "SELECT ReplyMark. * , Project.ProjectName, teacher.TeacherName, student.StudentName, student.StudentId
		FROM ReplyMark
		LEFT JOIN Project ON ReplyMark.Project_ProjectId = project.ProjectId
		LEFT JOIN teacher ON ReplyMark.Teacher_TeacherId = teacher.TeacherId
		LEFT JOIN student ON project.Student_StudentId = student.StudentId
		where student.StudentId=$student_id";
                                    $result_all = mysqli_query($conn, $sql_all);
                                    while ($row_all = mysqli_fetch_array($result_all)) {

                                        ?>
											<tr>
												<tr>
													<td>---</td>
													<td><?php echo $row_all['TeacherName'] ?></td>
													<td>---</td>
													<td>---</td>
													<td>---</td>
													<td><?php echo $row_all['Order8'] ?></td>
													<td><?php echo $row_all['Order9'] ?></td>
													<td><?php echo $row_all['Order10'] ?></td>
													<td><?php echo $row_all['Order11'] ?></td>
													<td><?php echo $row_all['remark'] ?></td>
												</tr>



											</tr>
											<?php
                                    }
                                } ?>





                                </tr>


                            </table>


                        </div>
                    </div>
                </div>

                <!--panel-foot-->

                <div class="panel-footer">
                    <form method="post" >
<!--                        <input type="text" class="maneger_input" id="search_text"/>-->
<!--                        <button class="maneger_button" type="submit">搜索</button>-->
                        <!--将所有成绩进行汇总，求平均分-->

                    </form>
                    <button class="maneger_button" class="btn" value="all" onclick="hz_one('one')">汇总</button>
                </div>

                <from>

            </div>
        </center>
    <? } ?>
</div>

<!--<footer class="indexfooter container-fluid  bottom">
    <p class="footer-p" align="center">地址：广东省广州市从化区经济开发区高技术产业园广从南路548号 | 电话：020－87818918 邮编：510990 | 网站公安备案编号：4401840100050 粤ICP备：05085382号 站长统计</p>
</footer>-->


<script>
    window.jQuery || document.write('<script src="../js/jquery-1.11.0.min.js"><\/script>')
</script>
<script type="text/javascript" src="../js/nav.js"></script>

</body>

</html>